﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace UI.Controllers
{
    public class PeixunController : Controller
    {
        //
        // GET: /Peixun/
        ServiceReference1.WebService1SoapClient web = new ServiceReference1.WebService1SoapClient();
        /// <summary>
        /// 培训记录表
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            List<ServiceReference1.train_tbModel> lst = web.peixunshow();
            return View(lst);
        }
        /// <summary>
        /// 类型
        /// </summary>
        /// <returns></returns>
        public string traintypeshow()
        {
            List<ServiceReference1.traintype_tbModel> typelst = web.traintypeshow();
            return JsonConvert.SerializeObject(typelst);
        }
        /// <summary>
        /// 人员
        /// </summary>
        /// <returns></returns>
        public string usershow()
        {
            List<ServiceReference1.Staff> lst = web.Ryxinxi().ToList();
            return JsonConvert.SerializeObject(lst);
        }
        /// <summary>
        /// 培训员工表
        /// </summary>
        /// <returns></returns>
        public ActionResult trainee()
        {
            return View();
        }
        /// <summary>
        /// 培训类型维护
        /// </summary>
        /// <returns></returns>
        public ActionResult traintype()
        {
            return View();
        }
        /// <summary>
        /// 培训类型显示
        /// </summary>
        /// <returns></returns>
        public string traintypeshow1()
        {

            List<ServiceReference1.traintype_tbModel> lst = web.traintypeshow();
            return JsonConvert.SerializeObject(lst); ;
        }
        /// <summary>
        /// 培训类型删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult traintypedel(int id)
        {
            int i = web.traintypedel(id);
            if (i > 0)
            {
                return Content("<script>alert('删除成功');location.href='/Peixun/traintype'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/Peixun/traintype'</script>");
            }
        }
        /// <summary>
        /// 培训类型添加，
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int traintypeadd(ServiceReference1.traintype_tbModel t)
        {
            int i = web.traintypeadd(t);
            return i;
        }
        /// <summary>
        /// 培训类型修改，
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int traintypeupt(ServiceReference1.traintype_tbModel t)
        {
            int i = web.traintypeupt(t);
            return i;
        }
        /// <summary>
        /// 培训类型反填
        /// </summary>
        /// <returns></returns>
        public string traintypeft(int id)
        {
            ServiceReference1.traintype_tbModel lst = web.traintypeft(id);
            return JsonConvert.SerializeObject(lst);
        }
        /// <summary>
        /// 员工证书
        /// </summary>
        /// <returns></returns>
        public ActionResult certificate_tb()
        {
            List<ServiceReference1.certificate_tbModel> lst = web.certificate_tb();
            return View(lst);
        }
        /// <summary>
        /// 人员表显示
        /// </summary>
        /// <returns></returns>
        public string traineeshow(int pageindex,int pagesize)
        {
            List<ServiceReference1.traineeModel> lst = web.traineeshow();
            Models.PeixunpageModel ptrainee = new Models.PeixunpageModel();
       
            ptrainee.trainee = lst.OrderBy(p => p.trainee_id).Skip(pagesize * (pageindex - 1)).Take(pagesize).ToList();
            ptrainee.count = web.traineeshow().Count();
            return JsonConvert.SerializeObject(ptrainee); ;
        }
        /// <summary>
        /// 人员表的删除，
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public ActionResult traineeDEL(int trainee_id)
        {
            int i = web.traineeDEL(trainee_id);
            if(i>0)
            {
                return Content("<script>alert('删除成功');location.href='/Peixun/trainee'</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/Peixun/trainee'</script>");
            }
        }
        /// <summary>
        /// 人员表的添加，
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int traineeADD(ServiceReference1.traineeModel t)
        {
            int i = web.traineeADD(t);
            return i;
        }
        /// <summary>
        /// 人员表的修改，
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int traineeUPT(ServiceReference1.traineeModel t)
        {
            int i = web.traineeUPT(t);
            return i;
        }
        /// <summary>
        /// 修改人员表反填
        /// </summary>
        /// <returns></returns>
        public string traineeft(int trainee_id)
        {
            List<ServiceReference1.traineeModel> lst = web.traineeft(trainee_id);
            return JsonConvert.SerializeObject(lst); 
        }
    }
}
